include-module.js ➔ includeModule   D
last analyzed

Complexity

Conditions 12

Size

Total Lines 54
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 54
rs 4.8
c 0
b 0
f 0
cc 12

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like include-module.js ➔ includeModule often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
function includeModule(module, plugin, el_id, success, error) {
2
    var elmnt = document.getElementById(el_id);
3
4
    var domain = '/origini-app/visitor/';
5
    var filename = '/';
0 ignored issues
show
Unused Code introduced by
The variable filename seems to be never used. Consider removing it.
Loading history...
6
    var file = domain + '' + module + '/plugin/' + plugin + '.html'; // + filename;
7
    var xhttp;
8
9
    if (typeof success !== 'function') {
10
        success = function () {
11
            console.log('success', "included");
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
12
        }
13
    }
14
15
    if (typeof error !== 'function') {
16
        error = function () {
17
            console.log('error', "Page not found.");
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
18
        }
19
    }
20
    console.log('file', file);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
21
22
    if (file) {
23
        /* Make an HTTP request using the attribute value as the file name: */
24
        xhttp = new XMLHttpRequest();
25
        xhttp.onreadystatechange = function () {
26
            if (this.readyState == 4) {
27
                if (this.status == 200) {
28
29
                    elmnt.innerHTML = this.responseText;
30
31
                    restModule(module,  '', '', '', function (data) {
32
                        console.error(data);
33
                        AddMessage(data.message.error);
34
                    }, function (data) {
35
                        console.table(data);
36
                        AddMessage(data.message.info);
37
                    });
38
39
                    success();
40
                }
41
                if (this.status == 404) {
42
                    error();
43
44
                }
45
                /* Remove the attribute, and call this function once more: */
46
                // includeHtml(file, success, error);
47
            }
48
        }
49
        xhttp.open("GET", file, true);
50
        xhttp.send();
51
        /* Exit the function: */
52
        return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
53
    }
54
}
55